package cn.getech.data.development.entity.flink;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@Data
@TableName(value = "bdp_real_flink_task_node")
public class FlinkTaskNode implements Serializable {
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 实时任务id 
     */
    @TableField(value = "task_id")
    private Integer taskId;
    /**
     * 资源id
     */
    @TableField(value = "source_id")
    private Integer sourceId;
    /**
     * 节点名称
     */
    @TableField(value = "node_name")
    private String nodeName;

    /**
     * 节点类型 1 source 2 select 3 filter 4 去重 5 group by 6 kafka 7 mysql
     */
    @TableField(value = "node_type")
    private Integer nodeType;

    /**
     * 英文表名
     */
    @TableField(value = "table_name")
    private String tableName;

    /**
     * 中文表名
     */
    @TableField(value = "table_alias")
    private String tableAlias;

    /**
     * 节点参数
     */
    @TableField(value = "node_param")
    private String nodeParam;

    /**
     * 目标表名称
     */
    @TableField(value = "target_table_name")
    private String targetTableName;

    /**
     * 表达式
     */
    @TableField(value = "expression")
    private String expression;

    /**
     * 分区
     */
    @TableField(value = "partition_by")
    private String partitionBy;

    /**
     * 排序
     */
    @TableField(value = "order_by")
    private String orderBy;

    /**
     * 字段名称
     */
    @TableField(value = "group_by")
    private String groupBy;

    /**
     * 是否使用窗口函数 1 是,0 否
     */
    @TableField(value = "windows_flag")
    private Integer windowsFlag;

    /**
     * 窗口函数字段名称
     */
    @TableField(value = "windows_field_name")
    private String windowsFieldName;

    /**
     * 窗口函数时间间隔
     */
    @TableField(value = "windows_interval")
    private String windowsInterval;

    /**
     * 创建者ID
     */
    @TableField(value = "create_per")
    private Long createPer;

    /**
     * 创建时间
     */
    @TableField(value = "create_time")
    private Date createTime;

    /**
     * 更新者ID
     */
    @TableField(value = "update_per")
    private Long updatePer;

    /**
     * 更新时间
     */
    @TableField(value = "update_time")
    private Date updateTime;

    /**
     * 删除 1 是,0 否
     */
    @TableField(value = "delete_flag")
    private Integer deleteFlag;

    private static final long serialVersionUID = 1L;

    public FlinkTaskNode(){}

    public FlinkTaskNode(Integer taskId,Integer sourceId, String nodeName, Integer nodeType, String tableName, String tableAlias,
                         String targetTableName, String expression, String partitionBy,
                         String orderBy, String groupBy, Integer windowsFlag,
                         String windowsFieldName, String windowsInterval) {
        this.taskId = taskId;
        this.sourceId=sourceId;
        this.nodeName = nodeName;
        this.nodeType = nodeType;
        this.tableName = tableName;
        this.tableAlias = tableAlias;
        this.targetTableName = targetTableName;
        this.expression = expression;
        this.partitionBy = partitionBy;
        this.orderBy = orderBy;
        this.groupBy = groupBy;
        this.windowsFlag = windowsFlag;
        this.windowsFieldName = windowsFieldName;
        this.windowsInterval = windowsInterval;
    }

    public void preSave(Long userId) {
        Date now = new Date();
        if (id == null) {
            this.createPer = userId;
            this.createTime = now;
        }
        this.updatePer = userId;
        this.updateTime = now;

    }
}